﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using CentrisScraper.Lib;
using log4net;
using log4net.Config;

namespace CentrisScraper.WindowsService
{
    public partial class Service : ServiceBase
    {
        public ScraperServiceRunner runner;

        public Service()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            XmlConfigurator.Configure();
            LogManager.GetLogger("Service").Error("Service.OnStart");
            PersistenceManager.Start();
            DisposeRunner();
            runner = ScraperServiceRunner.New();
        }

        protected override void OnStop()
        {
            DisposeRunner();
            PersistenceManager.Stop();
        }

        public new void Dispose()
        {
            DisposeRunner();
            PersistenceManager.Stop();
        }

        public void DisposeRunner()
        {
            if (runner != null)
            {
                runner.Stop();
            }
        }
    }
}
